package com.syq.controller;

import com.github.pagehelper.PageInfo;
import com.syq.dto.R;
import com.syq.pojo.SysCategory;
import com.syq.service.SysCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Sun Yueqi
 * @version 1.00
 * @time 2022/5/29 22:54
 */
@RestController
@RequestMapping("/categories")
public class SysCategoryController {
    private SysCategoryService categoryService;

    @Autowired
    public void setCategoryService(SysCategoryService categoryService) {
        this.categoryService = categoryService;
    }

    @PostMapping("/category")
    public R addCategory(@RequestBody SysCategory category){
        categoryService.addCategory(category);
        return R.setOk();
    }

    @GetMapping("/categories")
    public R findByPage(int pageSize,int pageNum){
       return R.setOk(categoryService.findByPage(pageSize, pageNum)) ;
    }

    @DeleteMapping("/category/{cId}")
    public R findById(Long cId){
        categoryService.deleteById(cId);
        return R.setOk();
    }
}
